<script setup lang="ts">
import { ref, reactive } from "vue";
import { templateRef } from "@vueuse/core";
import SeamlessScroll from "/@/components/ReSeamlessScroll";
import { postProjectTree } from "/@/api/project";

// const scroll = templateRef<ElRef | null>("scroll", null);
const scroll = templateRef("scroll", null);

// let listData = ref<ForDataType<undefined>>([
let listData = ref([]);

let classOption = reactive({
  direction: "top"
});

// 请求表格数据
const getTableData = async (obj: object = {}) => {
  try {
    const { code, data } = await postProjectTree(obj);
    if (code === 200) {
      listData.value = data.list.map(item => {
        return { date: item.createTime, name: item.projectName };
      });
    }
  } catch (err) {
    console.log(err);
  }
};

getTableData();
</script>

<template>
  <div class="infinite">
    <ul class="top">
      <li>创建日期</li>
      <li>项目名称</li>
      <!-- <li>Star数量</li> -->
    </ul>
    <SeamlessScroll
      ref="scroll"
      :data="listData"
      :class-option="classOption"
      class="warp"
    >
      <ul class="item">
        <li v-for="(item, index) in listData" :key="index">
          <span v-text="item.date"></span>
          <span v-text="item.name"></span>
          <!-- <span v-text="item.star"></span> -->
        </li>
      </ul>
    </SeamlessScroll>
  </div>
</template>

<style lang="scss" scoped>
.infinite {
  .top {
    width: 95%;
    height: 40px;
    line-height: 40px;
    display: flex;
    margin: 0 auto;
    font-size: 14px;
    color: #909399;
    font-weight: 400;
    background: #fafafa;

    li {
      width: 50%;
      text-align: center;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  .warp {
    width: 95%;
    height: 180px;
    margin: 0 auto;
    overflow: hidden;

    li {
      height: 30px;
      line-height: 30px;
      display: flex;
      font-size: 15px;
    }

    span {
      width: 50%;
      text-align: center;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
}
</style>
